package demo;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Main {
    //类斐波那契循环数
    public static void main1(String[] args) {

        for (int i = 10000000; i >= 197; i--) {
            if(check(i)==true) {
                System.out.println(i);
                //System.out.println(6065280);
                break;
            }
        }
    }

    private static boolean check(int i) {
        String str = String.valueOf(i);
        int val = i;
        int n = str.length();
        int sum = 0;
        List<Integer> list = new LinkedList<>();
        while(val>0) {
            sum += val%10;
            list.add(val%10);
            val /= 10;
        }
        int left = 0;
        int right = n-1;
        while(left<right) {
            int tmp = list.get(left);
            list.set(left, list.get(right));
            list.set(right, tmp);
            left++;
            right--;
        }
        list.add(sum);
        while(true) {
            if(list.get(list.size()-1) >= i) {
                if(list.get(list.size()-1) == i) {
                    System.out.println(list.get(list.size()-1));
                    return true;
                }else {
                    return false;
                }
            }
            if(i == 7913837) {
                System.out.println(list.get(list.size()-1));
                System.out.println(list.toString());
            }

            list.add(list.get(list.size()-1)*2 - list.get(0));
            list.remove(0);
        }
    }

    //分布式队列
//    public static void main(String []args){
//        Scanner sc = new Scanner(System.in);
//        int n = sc.nextInt();//节点数
//        int count[] = new int[n];//count用于记录每个节点队列的元素数,下标为0的是主节点
//        while(sc.hasNext()){
//          String op = sc.next();
//          if(op.equals("add")){
//            int x = sc.nextInt();
//            count[0]++;   //如果添加，主节点队列元素数加1
//          }else if(op.equals("sync")){
//            int x = sc.nextInt();
//            //副队列同步主队列，如果在执行这次操作时副队列已经是跟主队列相同了，此时再加1并不合理，最高就是跟主队列相同
//            count[x] = Math.min(count[x] + 1,count[0]);
//          }else{
//            int mi = count[0];//先假定主队列的所有数都可见，然后不断对比副队列去缩小个数
//            for(int i = 1;i < n; i++){//从1开始，因为下标0是主队列的元素个数
//              mi = Math.min(count[i],mi);//所有队列都有的才可见
//            }
//            System.out.println(mi);
//          }
//        }
//    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n+1];

        while(scanner.hasNext()) {
            String string = scanner.next();
            if("add".equals(string)) {
                nums[1]++;
            }else if("sync".equals(string)) {
                int index = scanner.nextInt()+1;
                nums[index] = Math.min(nums[index]+1, nums[1]);
                //System.out.println(Arrays.toString(nums));
            }else if("query".equals(string)){
                String val = scanner.next();
                //System.out.println(Arrays.toString(nums));
                int min = Integer.MAX_VALUE;
                for (int i = 1; i <= n; i++) {
                    min = Math.min(min, nums[i]);
                }
                System.out.println(min);
            }
        }
    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        float p = scanner.nextFloat();
        int MIN = 0x3f3f3f3f;
        int min = 0x3f3f3f3f;
        int T = (float)((n*p)-(int)(n*p))>0?(int)(n*p)+1:(int)(n*p);
        for (int i = 1; i <= n; i++) {
            if(n%i==0) {
                int key = n/i;
                int val = Math.min(T, key);
                if(MIN>key+val*i) {
                    MIN = key+val*i;
                    min = i;
                }
            }
        }
        System.out.println(min);
    }

    public static void test1(String[] args) {
        int key = 10;
        float p = 0.41f;
        int val = (float)((key*p)-(int)(key*p))>0?(int)(key*p)+1:(int)(key*p);
        System.out.println(val);
    }

    //星际穿越
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int Q = scanner.nextInt();
        int[] num1 = new int[2];
        int[] num2 = new int[2];
        for (int i = 0; i < m; i++) {
            num1[i] = scanner.nextInt();
        }
        for (int i = 0; i < Q; i++) {
            num2[i] = scanner.nextInt();
        }

    }
}
